package ControlLayer;

import java.util.*;
import DBLayer.*;
import ModelLayer.*;

public class AgencyCtr {
	private DiscountGroupCtr dgCtr;

	public AgencyCtr() {
		dgCtr = new DiscountGroupCtr();
	}

	public int insertAgency(String name, String phone, String email,
			String country, String address, int dgId) throws Exception {
		Agency agency = new Agency();
		agency.setName(name);
		agency.setPhone(phone);
		agency.setEmail(email);
		agency.setCountry(country);
		agency.setAddress(address);
		if (dgId == 0) {

		} else {
			DiscountGroup dg = dgCtr.getGroup(dgId);
			agency.setDiscountGroup(dg);
		}

		DBAgency dbAgency = new DBAgency();
		return dbAgency.insertAgency(agency);
	}

	public Agency getAgency(int ID) {
		IFDBAgency dbAgency = new DBAgency();
		return dbAgency.getAgency(ID, true);

	}

	public int deleteAgency(int ID) {
		IFDBAgency dbAgency = new DBAgency();
		return dbAgency.deleteAgency(ID);

	}

	// TODO
	public int updateAgency(int ID, String name, String phone, String email,
			String country, String address, int dgId) throws Exception {
		Agency agency = new Agency();
		agency.setId(ID);
		agency.setName(name);
		agency.setPhone(phone);
		agency.setEmail(email);
		agency.setCountry(country);
		agency.setAddress(address);
		if (dgId == 0) {

		} else {
			DiscountGroup dg = dgCtr.getGroup(dgId);
			agency.setDiscountGroup(dg);
		}

		int rc = 0;

		IFDBAgency dbAgency = new DBAgency();
		return dbAgency.updateAgency(agency);

	}

	public ArrayList<Agency> getAllAgency() {
		IFDBAgency dbAgency = new DBAgency();
		return dbAgency.getAllAgency(true);

	}

}
